# -*- conding:UTF-8 -*-

'''
@ Project: model
@ File: model.py
@ Author: 韩成瑾
@ Date：2022/8/7 19:24

'''
import random

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

from datetime import datetime

# 用户和朋友的关系表
# user_friends = db.Table(
#     'user_friends',
#     db.Column('id',db.Integer,primary_key=True,autoincrement=True),
#     db.Column('user_id',db.Integer,db.ForeignKey('User')),
#     db.Column('friend_id',db.Integer,db.ForeignKey('Friends')),
#     db.UniqueConstraint('user_id','friend_id',name='')
# )




class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, nullable=True, comment='ID')
    img = db.Column(db.String(128), default='', comment='头像')
    mobile = db.Column(db.String(11),comment='手机号')
    code = db.Column(db.String(64),default=random.randint(1000,9999),comment='验证码')
    name = db.Column(db.String(12), comment='用户姓名')
    friend_id = db.relationship('Friends',backref='user')
    cicrle_id = db.relationship('Cicrle',backref='user')


class Friends(db.Model):
    id = db.Column(db.Integer, primary_key=True, nullable=True, comment='ID')
    img = db.Column(db.String(128), default='', comment='头像')
    name = db.Column(db.String(12),comment='备注名字')
    group = db.Column(db.Integer,comment='分组(1.家人;2.朋友;3.同学)')
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'))


class Cicrle(db.Model):
    id = db.Column(db.Integer, primary_key=True, nullable=True, comment='ID')
    content = db.Column(db.String(50),comment='内容')
    img = db.Column(db.String(125),default='',comment='图片')
    backref = db.Column(db.String(128), default='', comment='背景图片')
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'))


